package com.lovo.system.frame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.lovo.common.model.CutPageBean;
import com.lovo.common.model.LogBean;
import com.lovo.emp.frame.EmpAddDialog;
import com.lovo.emp.frame.EmpPanel;
import com.lovo.emp.frame.EmpShowDialog;
import com.lovo.emp.frame.EmpUpdateDialog;
import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoComboBox;
import com.lovo.netCRM.component.LovoCutPage;
import com.lovo.netCRM.component.LovoDate;
import com.lovo.netCRM.component.LovoList;
import com.lovo.netCRM.component.LovoTable;
import com.lovo.netCRM.component.LovoTitleLabel;
import com.lovo.netCRM.component.LovoTitlePanel;
import com.lovo.netCRM.component.LovoTxt;
import com.lovo.system.service.ILogService;
import com.lovo.system.service.impl.LogServiceImpl;

/**
 * 日志一览主面板
 * @author 白德柯
 *
 */
public class LogPanel extends JPanel{


	/**学校统计表格组件*/
	private LovoTable logTable;
	/**窗体组件*/
	private JFrame jf;
	/**起始日期*/
	private LovoDate startDate;
	/**结束日期*/
	private LovoDate endDate;

	private ILogService logService = new LogServiceImpl();

	/**分页对象*/
	private LovoCutPage cutPage;
	public LogPanel(JFrame jf){
		this.jf = jf;
		this.setLayout(null);
		this.init();
	}
	/**
	 * 初始化
	 *
	 */
	private void init() {
		new LovoTitleLabel("日 志 一 览",this);
		this.initTable();
		this.initFindPanel();
		this.initData();
	}
	/**
	 * 初始化数据
	 */
	public void initData(){
		this.updateTable(1);
	}
	
	

	
	//-------------------------------------------------
	/**
	 * 初始化表格
	 *
	 */
	private void initTable() {
		logTable = new LovoTable(this,
				new String[]{"日期","内容"},
				new String[]{"createDate","logInfo"},//日期实体属性名数组
				"id");//主键属性名
		logTable.setSizeAndLocation(20, 90, 700, 300);
		// 分页
		cutPage = new LovoCutPage(20,400,this) {
			@Override
			public void clickEvent(int page) {
				updateTable(page);
			}
		};
	}
	
	
	/**
	 * 初始化查询按钮
	 *
	 */
	private void initFindPanel(){

		LovoTitlePanel jp = new LovoTitlePanel("按录入时间查询",400, 460, 320, 130,this);
		this.startDate = new LovoDate("起始日期",30,30,jp);
		this.endDate = new LovoDate("结束日期",30,60,jp);
		
		LovoButton findButton = new LovoButton("查找",180,90,jp);
		findButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				updateTable(1);
			}
		});
		findButton.setSize(60, 20);

		
	}
	
	/**
	 * 更新表格数据
	 */
	private void updateTable(int page){
		String startDateValue = startDate.getText();
		String endDateValue = endDate.getText();
		CutPageBean<LogBean> cutPageBean = logService.findByItem(page,startDateValue,endDateValue);
		//更新表格
		logTable.updateLovoTable(cutPageBean.getList());
		if(page == 1){
			cutPage.setTotalPage(cutPageBean.getTotalPage());
		}
	}

}
